/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.serialportmodule.services;

import org.testis.data.TestStepException;
import org.testis.data.TestStepResultType;
import org.testis.logging.AtofLogLevel;
import org.testis.logging.LogSenderService;
import org.testis.serialportmodule.data.SerialPortModuleDataObject;
import org.testis.services.AtofModuleAction;
import org.testis.services.AtofModuleService;


/**
 *
 * @author root
 */
public class SerialPortModuleStartConnectionAction extends AtofModuleAction
{

    @Override
    public boolean operateRequest(AtofModuleService request)
    {


        SerialPortModuleProviderService service =
            (SerialPortModuleProviderService) request;
        SerialPortModuleDataObject dataObj =
            (SerialPortModuleDataObject) service.getDataObj();
        try {

            LogSenderService.putMessageOnQueue(
                "SerialPortModuleStartConnectionAction",
                AtofLogLevel.INFO,
                "Starting serial connection on port COM" + dataObj.getComPortNo(),
                dataObj.getMessageId());
             if (service.m_serialConnection == null) {
                LogSenderService.putMessageOnQueue(
                        "SerialPortModuleStartConnectionAction",
                        AtofLogLevel.INFO,
                        "No active serial connection found. Can not start connection... ",
                        dataObj.getMessageId());
                return false;
            }
            return service.m_serialConnection.startConnection();

        } catch (Exception ex) {
            throw new TestStepException(TestStepResultType.FAILURE,
                                        ex.getMessage());
        }
    }
}
